.386
.model flat, stdcall
option casemap:none


includelib msvcrt.lib
includelib user32.lib
includelib kernel32.lib


printf PROTO C : ptr sbyte, :VARARG
scanf PROTO C : ptr sbyte, :VARARG


.data
printIntFormat db '%d',0ah,0
printStrFormat db '%s',0ah,0
scanIntFormat db '%d',0
StrConst_0 db "Please input a number:\n", 0
StrConst_1 db "The number of prime numbers within n is:\n", 0
.code
Mars_PrintStr PROC outStr:ptr sbyte
	invoke printf, offset printStrFormat, outStr
	ret
Mars_PrintStr endp
Mars_PrintInt PROC outInt:SDWORD
	invoke printf, offset printIntFormat, outInt
	ret
Mars_PrintInt endp
Mars_GetInt PROC
LOCAL tmp:SDWORD
	invoke scanf, offset scanIntFormat, ADDR tmp
	mov eax, tmp
	ret
Mars_GetInt endp
prime	PROC	_n:SDWORD
	LOCAL tmpVar_22 : DWORD
	LOCAL tmpVar_21 : DWORD
	LOCAL tmpVar_20 : DWORD
	LOCAL tmpVar_17 : DWORD
	LOCAL tmpVar_16 : DWORD
	LOCAL tmpVar_13 : DWORD
	LOCAL tmpVar_12 : DWORD
	LOCAL tmpVar_11 : DWORD
	LOCAL tmpVar_10 : DWORD
	LOCAL tmpVar_5 : DWORD
	LOCAL _flag : SDWORD
	LOCAL _j : SDWORD
	LOCAL _i : SDWORD
	LOCAL _sum : SDWORD
	mov eax, 0
	mov _sum, eax
	mov eax, 1
	mov _flag, eax
	mov eax, 2
	mov _i, eax
Flag_1 : 
	mov eax, _i
	mov ebx, _n
	cmp eax, ebx
	JG Flag_2
Flag_3 : 
	mov eax, 1
	mov _flag, eax
	mov eax, 2
	mov _j, eax
Flag_6 : 
	mov eax, _j
	cdq
	mov ebx, _j
	imul ebx
	mov tmpVar_11, eax
	mov eax, tmpVar_11
	mov ebx, _i
	cmp eax, ebx
	JG Flag_7
Flag_8 : 
	mov eax, _i
	cdq
	mov ebx, _j
	idiv ebx
	mov tmpVar_13, edx
	mov eax, tmpVar_13
	mov ebx, 0
	cmp eax, ebx
	JNE Flag_14
	mov eax, 0
	mov _flag, eax
	JMP Flag_15
Flag_14:
Flag_15:
	JMP Flag_9
Flag_9 : 
	mov eax, _j
	mov tmpVar_16, eax
	inc _j
	JMP Flag_6
Flag_7 : 
	mov eax, _flag
	mov ebx, 1
	cmp eax, ebx
	JNE Flag_18
	mov eax, _sum
	mov tmpVar_20, eax
	inc _sum
	invoke Mars_PrintInt, _i
	mov tmpVar_21, eax
	JMP Flag_19
Flag_18:
Flag_19:
	JMP Flag_4
Flag_4 : 
	mov eax, _i
	mov tmpVar_22, eax
	inc _i
	JMP Flag_1
Flag_2 : 
	mov eax, _sum
	ret
prime	endp
main	PROC	
	LOCAL tmpVar_27 : DWORD
	LOCAL tmpVar_26 : DWORD
	LOCAL _res : SDWORD
	LOCAL tmpVar_25 : DWORD
	LOCAL _n : SDWORD
	LOCAL tmpVar_24 : DWORD
	LOCAL tmpVar_23 : DWORD
	invoke Mars_PrintStr, offset StrConst_0
	mov tmpVar_23, eax
	invoke Mars_GetInt
	mov tmpVar_24, eax
	mov eax, tmpVar_24
	mov _n, eax
	invoke prime, _n
	mov tmpVar_25, eax
	mov eax, tmpVar_25
	mov _res, eax
	invoke Mars_PrintStr, offset StrConst_1
	mov tmpVar_26, eax
	invoke Mars_PrintInt, _res
	mov tmpVar_27, eax
	mov eax, 0
	ret
main	endp
AsmStart:
	invoke main
	ret
end AsmStart
